import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'

const resolve = (dir: string) => path.join(__dirname, dir)

export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      // 设置路径
      '~': resolve('./'),
      '@': resolve('/src'),
      'comps': resolve('src/components'),
      'apis': resolve('src/apis'),
      'views': resolve('src/views'),
      'utils': resolve('src/utils'),
      'routes': resolve('src/routes'),
      'styles': resolve('src/styles'),
      'workers': resolve('src/workers'),
      'plugins': resolve('src/plugins')
    }
  },
  server: {
    host: '0.0.0.0', //ip地址
    port: 8888, //端口号
    open: true, //启动后是否自动打开浏览器
    proxy: {
      '/dev-api': {
        target: 'http://127.0.0.1:8090',
        changeOrigin: true,
        rewrite: (p) => p.replace(/^\/dev-api/, '')
      }
    }
  }
})
